<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      v-show="showSearch"
      :inline="true"
      label-width="80px"
    >
      <el-form-item label="考试类型" prop="category">
        <el-select
          v-model="queryParams.category"
          placeholder="考试类型"
          clearable
          size="small"
          style="width: 240px"
          @change="handleQuery"
        >
          <el-option
            v-for="item in cateOptions"
            :key="item.id"
            :label="item.label"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="关键字" prop="keywords">
        <el-input
          v-model="queryParams.keywords"
          placeholder="请输入试卷名称/发布人"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
          size="small"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          v-hasPermi="['21310']"
          @click="handleAdd"
          >添加考试</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="tableList"
      :border="true"
      style="margin-top: 0"
    >
      <!-- <el-table-column label="考试ID" prop="userName" align="center"/> -->
      <el-table-column
        align="center"
        prop="thePic"
        label="考试图片"
        width="80"
      >
        <template slot-scope="scope">
          <imagePreview :src="scope.row.thePic" />
        </template>
      </el-table-column>
      <el-table-column
        label="考试类型"
        prop="typeVal"
        align="center"
        width="160"
      />
      <el-table-column
        label="考试名称"
        prop="title"
        align="center"
        :show-overflow-tooltip="true"
        width="120"
      >
        <template slot-scope="scope">
          <span @click="handleSee(scope.row)" class="active">
            {{ scope.row.title }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        label="出题方式"
        prop="paperType"
        align="center"
        width="100"
      >
        <template slot-scope="scope">
          <span v-if="scope.row.paperType === 1">随机试题</span>
          <span v-if="scope.row.paperType === 0">固定试题</span>
        </template>
      </el-table-column>
      <el-table-column
        label="班组名称"
        prop="shift"
        align="center"
        :show-overflow-tooltip="true"
        width="120"
      >
        <template slot-scope="scope">
          <span @click="handleTeam(scope.row)" class="active">
            {{ scope.row.shift }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        label="培训人数"
        prop="personnelNum"
        align="center"
        width="80"
      />
      <el-table-column
        label="考试题库"
        prop="questionCategory"
        align="center"
        :show-overflow-tooltip="true"
        width="120"
      >
        <!-- <template slot-scope="scope">
          <span @click="handleQuest(scope.row)" class="active">
            {{ scope.row.title }}
          </span>
        </template> -->
      </el-table-column>
      <el-table-column
        label="考试时长"
        prop="duration"
        align="center"
        :show-overflow-tooltip="true"
        width="100"
      />
      <el-table-column
        label="试题数量"
        prop="questionNum"
        align="center"
        :show-overflow-tooltip="true"
        width="100"
      />
      <el-table-column
        label="试卷总分"
        prop="totalScore"
        align="center"
        :show-overflow-tooltip="true"
        width="100"
      />
      <el-table-column
        label="及格分数"
        prop="passLine"
        align="center"
        :show-overflow-tooltip="true"
        width="100"
      />
      <el-table-column
        label="开考时间"
        prop="startTime"
        align="center"
        :show-overflow-tooltip="true"
        width="170"
      />
      <el-table-column
        label="结束时间"
        prop="endTime"
        align="center"
        :show-overflow-tooltip="true"
        width="170"
      />
      <!-- <el-table-column label="发布（是/否）" align="center" key="releaseStatus">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.releaseStatus"
            active-value="0"
            inactive-value="1"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column> -->

      <el-table-column
        label="发布人"
        prop="publisher"
        align="center"
        :show-overflow-tooltip="true"
        width="120"
      />
      <el-table-column
        label="发布时间"
        prop="releaseTime"
        align="center"
        :show-overflow-tooltip="true"
        width="120"
      />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        fixed="right"
        width="120"
      >
        <template slot-scope="scope">
          <!-- <el-button size="mini" type="text" @click="handleCode(scope.row)"
            >考试二维码</el-button
          > -->
          <!-- "releaseStatus": 0, //发布情况 0-待发布 1-已发布
                0  显示按钮：考试二维码 修改 删除 发布
                0  显示按钮：考试二维码 取消发布
           -->
          <el-button
            v-if="scope.row.releaseStatus === 0"
            size="mini"
            v-hasPermi="['21320']"
            type="text"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            v-if="scope.row.releaseStatus === 0"
            size="mini"
            v-hasPermi="['21330']"
            type="text"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
          <el-button
            v-if="scope.row.releaseStatus === 0"
            size="mini"
            type="text"
            @click="handleRelease(scope.row)"
            >发布</el-button
          >
          <el-button
            v-if="scope.row.releaseStatus === 1"
            size="mini"
            type="text"
            @click="Unpublish(scope.row)"
            >取消发布</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.currentPage"
      :limit.sync="queryParams.pagesize"
      @pagination="getList"
    />
    <!-- 二维码 -->
    <el-dialog
      width="500px"
      :visible.sync="open4"
      title="二维码"
      class="qrcode"
    >
      <!-- <img :src="qrcode" alt="" /> -->
      <img :src="qrcode2" alt="" />
    </el-dialog>
    <!-- 添加或修改角色配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="650px" append-to-body>
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        :validate-on-rule-change="false"
        label-width="110px"
      >
        <el-form-item label="考试类型" prop="typeId">
          <treeselect
            v-model="form.typeId"
            :options="cateOptions"
            :show-count="true"
            placeholder="请选择考试类型"
            @select="seleExamkinds"
          />
        </el-form-item>
        <el-form-item label="考试试卷" prop="paperId">
          <el-select
            v-model="form.paperId"
            @change="changeExampaper"
            placeholder="请选择"
          >
            <el-option
              v-for="item in ExampapersOptions"
              :key="item.theid"
              :label="item.title"
              :value="item.theid"
            ></el-option>
          </el-select>
          <!-- <treeselect
            v-model="form.paperId"
            :options="ExampapersOptions"
            :show-count="true"
            placeholder="请选择考试试卷"
            @select="seleExampaper"
          /> -->
        </el-form-item>
        <!-- 考试任务   增加  任务类型 1-独立考试 2-培训考试 -->
        <el-form-item label="任务类型" prop="taskType">
          <el-radio-group v-model="form.taskType">
            <el-radio :label="1">独立考试</el-radio>
            <el-radio :label="2">培训考试</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="考试图片" prop="thePic">
          <uploadImage v-model="form.thePic" />
        </el-form-item>

        <el-form-item label="考试名称" prop="title">
          <el-input v-model="form.title" placeholder="请输入考试名称" />
        </el-form-item>
        <el-form-item label="考试时间" prop="startTime">
          <el-date-picker
            v-model="dateRange"
            type="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="changeDate"
          >
          </el-date-picker>
        </el-form-item>
        <!-- <el-form-item label="开考时间" prop="startTime">
          <el-date-picker
            v-model="form.duration"
            type="datetime"
            placeholder="选择日期时间"
            default-time="09:00:00"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-date-picker
            v-model="form.duration"
            type="datetime"
            placeholder="选择日期时间"
            default-time="12:00:00"
          >
          </el-date-picker>
        </el-form-item> -->
        <el-form-item label="考试部门" prop="departmentId">
          <treeselect
            v-model="form.departmentId"
            :options="deptOptions"
            :show-count="true"
            placeholder="请选择考试部门"
            size="small"
            @select="seledepartment"
          />
        </el-form-item>
        <!-- <el-form-item label="考试须知" prop="instructions">
          <el-input
            v-model="form.instructions"
            type="textarea"
            autosize
            placeholder="请输入内容"
          />
        </el-form-item> -->

        <el-form-item label="考试班组" prop="shiftId">
          <el-select
            v-model="form.shiftId"
            @change="changeExamteam"
            placeholder="请选择"
          >
            <el-option
              v-for="item in examteamOptions"
              :key="item.theid"
              :label="item.title"
              :value="item.theid"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考试须知" prop="instructions">
          <editor v-model="form.instructions" :min-height="192" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看试题 试卷预览 -->
    <el-dialog
      :title="title2"
      :visible.sync="open2"
      width="700px"
      append-to-body
      @close="closeSee"
    >
      <div class="checktitle">
        <p>答卷时长：{{ examPaper.duration }}</p>
        <p>试题总分：{{ examPaper.totalScore }}</p>
        <p>及格线：{{ examPaper.passLine }}</p>
      </div>
      <!-- 单选 -->
      <div class="topickinds" v-if="questionList[0].title != ''">
        <p>{{ questionList[0].title }}</p>
        <div class="topic">
          <div
            v-for="item in questionList[0].children"
            :key="item.theid"
            class="topiclist"
          >
            {{ item.subject }}
            <el-radio-group class="option" disabled>
              <el-radio
                v-for="ele in item.options"
                :key="ele.val"
                :value="ele.val"
                :label="ele.val"
                >{{ ele.val + ele.title }}</el-radio
              >
            </el-radio-group>
          </div>
        </div>
      </div>
      <!-- 多选 -->
      <div class="topickinds" v-if="questionList[1].title != ''">
        <p>{{ questionList[1].title }}</p>
        <div class="topic">
          <div
            v-for="item in questionList[1].children"
            :key="item.theid"
            class="topiclist"
          >
            {{ item.subject }}
            <p class="option">
              <el-checkbox-group disabled>
                <el-checkbox
                  v-for="ele in item.options"
                  :key="ele.val"
                  :label="ele.val"
                  >{{ ele.val + ele.title }}</el-checkbox
                >
              </el-checkbox-group>
            </p>
          </div>
        </div>
      </div>
      <!-- 判断 -->
      <div class="topickinds" v-if="questionList[2].title != ''">
        <p>{{ questionList[2].title }}</p>
        <div class="topic">
          <div
            v-for="item in questionList[2].children"
            :key="item.theid"
            class="topiclist"
          >
            {{ item.subject }}
            <el-radio-group class="option" disabled>
              <el-radio
                v-for="ele in item.options"
                :key="ele.val"
                :value="ele.val"
                :label="ele.val"
                >{{ ele.val + "、" + ele.title }}</el-radio
              >
            </el-radio-group>
          </div>
        </div>
      </div>
      <!-- 填空 -->
      <div class="topickinds" v-if="questionList[3].title != ''">
        <p>{{ questionList[3].title }}</p>
        <div class="topic">
          <div
            v-for="item in questionList[3].children"
            :key="item.theid"
            class="topiclist"
          >
            {{ item.subject }}
            <!-- <input type="text" /> 。 -->
          </div>
        </div>
      </div>
    </el-dialog>
    <!-- 发布 -->
    <el-dialog
      title="培训任务发布"
      :visible.sync="openPublish"
      width="700px"
      append-to-body
    >
      <el-form
        ref="formPublish"
        :model="formPublish"
        :rules="rules"
        label-width="80px"
      >
        <el-form-item label="发布时间" prop="reviewTime">
          <el-date-picker
            v-model="formPublish.reviewTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="选择日期时间"
            default-time="12:00:00"
            :clearable="false"
          >
          </el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPublish">确 定</el-button>
        <el-button @click="cancelPublish">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 发布人员 -->
    <el-dialog :title="title" :visible.sync="openperson" append-to-body>
      <!-- 
        企业员工：部门、工作单位（可显示/可不显示）、岗位
        外委人员：工作单位
       -->
      <el-table
        v-loading="personLoading"
        :data="personList"
        max-height="400px"
        :border="true"
      >
        <el-table-column label="姓名" prop="fullName" align="center" />
        <el-table-column v-if="ispeople==1" label="部门" prop="department" align="center" />
        <el-table-column v-if="ispeople==2" label="工作单位" prop="workUnit" align="center" />
        <el-table-column label="工种" prop="workType" align="center" />
        <el-table-column v-if="ispeople == 1" label="岗位" prop="post" align="center" />
        <el-table-column label="发布状态" align="center" key="sendStatus">
          <template slot-scope="scope">
            <span v-if="scope.row.sendStatus === 0">待发布</span>
            <span v-if="scope.row.sendStatus === 1">已发布</span>
          </template>
        </el-table-column>
        <el-table-column label="消息读取" align="center" key="reviewStatus">
          <template slot-scope="scope">
            <span v-if="scope.row.reviewStatus === 0">待读取</span>
            <span v-if="scope.row.reviewStatus === 1">已读取</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="personTotal > 0"
        :total="personTotal"
        :page.sync="personParams.currentPage"
        :limit.sync="personParams.pagesize"
        @pagination="getPersonList"
      />
    </el-dialog>

    <!-- 设置题库 弹框 -->
    <el-dialog :title="title" :visible.sync="questbank">
      <el-form
        ref="form"
        :model="form"
        :rules="rules"
        :validate-on-rule-change="false"
        label-width="140px"
      >
        <el-form-item label="试卷类型" prop="userName" :required="true">
          <el-radio v-model="radio" label="1">随机试题</el-radio>
          <el-radio
            v-model="radio"
            label="2"
            @click.native.prevent="handleColumnsConfig"
            >固定试题</el-radio
          >
        </el-form-item>

        <el-form-item label="题库分类" prop="curriculumType" :required="true">
          <treeselect
            v-model="queryParams.curriculumType"
            :options="courseOptions"
            :show-count="true"
            placeholder="请选择题库分类"
            size="small"
          />
        </el-form-item>
        <el-form-item label="题库列表" prop="curriculumType" :required="true">
          <treeselect
            v-model="queryParams.curriculumType"
            :options="courseOptions"
            :show-count="true"
            placeholder="请选择题库列表"
            size="small"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 选择题库弹框 -->
    <!-- <el-dialog width="700px" :visible.sync="open3" :title="title3">
      <el-form label-width="140px">
        <el-form-item label="试题总数" prop="duration">
          <el-input v-model="form.duration" placeholder="请输入试题总数" />
        </el-form-item>

        <el-form-item label="试卷总分" prop="totalScore">
          <el-input
            v-model="form.totalScore"
            disabled
            placeholder="请输入总分"
          />
        </el-form-item>
        <el-form-item label="单选题数量" prop="userName">
          <el-input
            v-model="form.rules.singleNum"
            type="number"
            placeholder="单选题数量"
          />
        </el-form-item>
        <el-form-item label="多选题数量" prop="userName">
          <el-input
            v-model="form.rules.multipleNum"
            type="number"
            placeholder="多选题数量"
          />
        </el-form-item>
        <el-form-item label="判断题数量" prop="userName">
          <el-input
            v-model="form.rules.judgNum"
            type="number"
            placeholder="判断题数量"
          />
        </el-form-item>
        <el-form-item label="填空题数量" prop="userName">
          <el-input
            v-model="form.rules.completionNum"
            type="number"
            placeholder="填空题数量"
          />
        </el-form-item>
        <el-form-item label="试卷类型" prop="userName" :required="true">
          <el-radio
            v-model="radio1"
            label="1"
            @click.native.prevent="handleRandom"
            >随机试题</el-radio
          >
          <el-radio v-model="radio1" label="2">固定试题</el-radio>
        </el-form-item>

        <el-form-item label="题库分类" prop="curriculumType" :required="true">
          <treeselect
            v-model="queryParams.curriculumType"
            :options="courseOptions"
            :show-count="true"
            placeholder="请选择题库分类"
            size="small"
          />
        </el-form-item>
        <el-form-item label="题库列表" prop="curriculumType" :required="true">
          <treeselect
            v-model="queryParams.curriculumType"
            :options="courseOptions"
            :show-count="true"
            placeholder="请选择题库列表"
            size="small"
          />
        </el-form-item>
        <el-form-item label="试题列表" prop="menuIds" :required="true">
          <el-checkbox
            v-model="menuExpand"
            @change="handleCheckedTreeExpand($event, 'menu')"
            >展开/折叠</el-checkbox
          >
          <el-checkbox
            v-model="menuNodeAll"
            @change="handleCheckedTreeNodeAll($event, 'menu')"
            >全选/全不选</el-checkbox
          >
          <el-checkbox
            v-model="menuCheckStrictly"
            @change="handleCheckedTreeConnect($event, 'menu')"
            >父子联动</el-checkbox
          >
          <el-tree
            class="tree-border"
            :data="data"
            show-checkbox
            ref="menu"
            node-key="id"
            :check-strictly="!menuCheckStrictly"
            empty-text="加载中，请稍后"
            :props="defaultProps"
          ></el-tree>
           :data = "menuOptions" -->
    <!--   </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog> -->
  </div>
</template>

<script>
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import UploadImage from "@/components/ImageUpload";
import Editor from "@/components/Editor";

import {
  listData,
  getData,
  delData,
  addData,
  updateData,
  delMultiData,
  getSelect,
  getEnable,
  Examinationteam,
  getExampapers,
  getCrewpopel,
  getPublish,
  getUnpublish,
} from "@/api/check/testTask";
import { getPaper } from "@/api/check/problemSet";

export default {
  name: "testTask",
  data() {
    return {
      ispeople: "",
      qrcode2: "http://data.aqykt.cn/storage/test/2wm-1.jpg",
      qrcode: "",
      dateRange: [],
      value1: [new Date(), new Date()],
      status: "0",
      // status:false,
      menuExpand: false,
      menuNodeAll: false,
      menuCheckStrictly: true,
      // 菜单列表
      menuOptions: [],
      courseOptions: [],
      cateOptions: [], //考试类型
      levelOptions: [], //考试级别
      placeOptions: [], //考试地点
      modeOptions: [], //考试方式
      deptOptions: [], //考试部门
      examteamOptions: [], // 考试班组
      ExampapersOptions: [], // 考试试卷
      queryParams: {
        currentPage: 1,
        pagesize: 10,
        keywords: undefined,
        category: undefined,
        examMode: undefined, //考试方式 id
        examLevel: undefined, //考试级别 id
        examPlace: undefined, //考试地点 id
        department: undefined, //考试部门 id
        startTime: undefined, //考试开始时间
        endTime: undefined, //考试结束时间
      },
      loading: true,
      tableList: [
        // {
        //   userName: "sdff",
        //   img: "",
        //   title: "数理化",
        // },
      ],
      total: 0,

      data: [
        {
          id: 1,
          label: "一级 1",
          children: [
            {
              id: 4,
              label: "二级 1-1",
              children: [
                {
                  id: 9,
                  label: "三级 1-1-1",
                },
                {
                  id: 10,
                  label: "三级 1-1-2",
                },
              ],
            },
          ],
        },
        {
          id: 2,
          label: "一级 2",
          children: [
            {
              id: 5,
              label: "二级 2-1",
            },
            {
              id: 6,
              label: "二级 2-2",
            },
          ],
        },
        {
          id: 3,
          label: "一级 3",
          children: [
            {
              id: 7,
              label: "二级 3-1",
            },
            {
              id: 8,
              label: "二级 3-2",
            },
          ],
        },
      ],
      defaultProps: {
        children: "children",
        label: "label",
      },
      radio: "1",
      radio1: "2",
      checkList: ["选中且禁用", "复选框 A"],
      /**查询 */
      // 查询参数

      // 部门树选项
      deptOptions: undefined,
      // 显示搜索条件
      showSearch: true,
      /** 弹框部分-------- */
      // 弹出层标题
      title: "",
      title1: "",
      title2: "查看",
      title3: "选择题库",
      // 是否显示弹出层
      open: false,
      open1: false,
      open3: false,
      open4: false,
      questbank: false,
      // 表单参数
      form: {
        rules: {
          singleNum: undefined,
          singleVal: undefined,
          multipleNum: undefined,
          multipleVal: undefined,
          judgNum: undefined,
          judgVal: undefined,
          completionNum: undefined,
          completionVal: undefined,
        },
      },
      // 表单校验
      rules: {
        typeId: [
          { required: true, message: "请选择考试类型", trigger: "blur" },
        ],
        // thePic: [
        //   { required: true, message: "考试图片不能为空", trigger: "blur" },
        // ],
        title: [
          { required: true, message: "考试名称不能为空", trigger: "blur" },
        ],
        departmentId: [
          { required: true, message: "请选择考试部门", trigger: "blur" },
        ],
        startTime: [
          { required: true, message: "请选择培训时间", trigger: "change" },
        ],
        paperId: [
          { required: true, message: "请选择考试试卷", trigger: "change" },
        ],
        shiftId: [
          { required: true, message: "请选择考试班组", trigger: "change" },
        ],
      },
      // 培训任务发布
      openPublish: false,
      formPublish: {
        reviewerId: this.$store.state.userInfo.theid,
        reviewer: this.$store.state.userInfo.thename,
      },
      // 发布人员
      openperson: false,
      personLoading: false,
      personParams: {
        currentPage: 1,
        pagesize: 10,
      },
      personTotal: 0,
      personList: [],
      // 查看试卷
      open2: false,
      examPaper: {},
      questionList: [
        { title: "", children: [] },
        { title: "", children: [] },
        { title: "", children: [] },
        { title: "", children: [] },
      ],
    };
  },
  computed: {},
  watch: {},
  components: { UploadImage, Treeselect, Editor },
  created() {
    this.getList();
    this.getSelect();
    this.getExamteam();
    this.getExampapers();
  },
  methods: {
    // 考试班组 下拉
    getExamteam() {
      Examinationteam(this.queryParams).then((response) => {
        console.log("response-----", response);
        this.examteamOptions = response.result.rows;
      });
    },
    // 树权限（展开/折叠）
    handleCheckedTreeExpand(value, type) {
      let treeList = this.data;
      for (let i = 0; i < treeList.length; i++) {
        this.$refs.menu.store.nodesMap[treeList[i].id].expanded = value;
      }
    },
    // 树权限（全选/全不选）
    handleCheckedTreeNodeAll(value, type) {
      this.$refs.menu.setCheckedNodes(value ? this.data : []);
    },
    // 树权限（父子联动）
    handleCheckedTreeConnect(value, type) {
      this.menuCheckStrictly = value ? true : false;
    },
    getList() {
      this.loading = true;
      listData(this.queryParams).then((response) => {
        // console.log('response-----',response);
        this.tableList = response.result.rows;
        this.total = response.result.total;
        this.loading = false;
      });
    },
    // 考试类型
    seleExamkinds(val) {
      if (this.cateOptions.length > 0) {
        this.form.typeVal = val.label;
      }
      // this.form.classificationId = undefined;
      // console.log(this.form.typeVal);
      // this.getClassTree(val.id);
    },

    // 考试部门
    seledepartment(val) {
      if (this.deptOptions.length > 0) {
        this.form.department = val.label;
      }
    },
    getExampapers() {
      getExampapers(this.queryParams).then((response) => {
        console.log(response);
        this.ExampapersOptions = response.result.rows;
        console.log(this.ExampapersOptions);
      });
    },
    changeExamteam(val) {
      //考试班组
      if (this.examteamOptions.length > 0) {
        this.form.shift = val
          ? this.examteamOptions.find((ele) => ele.theid === val).title
          : "";
        this.form.personnelNum = val
          ? this.examteamOptions.find((ele) => ele.theid === val).personnelNum
          : "";
      }
    },
    changeExampaper(val) {
      //考试试卷
      if (this.ExampapersOptions.length > 0) {
        this.form.paper = val
          ? this.ExampapersOptions.find((ele) => ele.theid === val).title
          : "";
      }
      console.log(this.form.paper);
    },
    changeTypeVal2(val) {
      if (val === 1) this.form.typeVal2val = "独立考试";
      else if (val === 1) this.form.typeVal2val = "培训考试";
    },
    // 考试类型 下拉框
    getSelect() {
      getSelect().then((response) => {
        this.cateOptions = response.result.examCategory; //考试类型
        this.levelOptions = response.result.examLevel; //考试级别
        this.placeOptions = response.result.examPlace; //考试地点
        this.modeOptions = response.result.examMode; //考试方式
        this.deptOptions = response.result.department; //考试部门
      });
    },

    handleQuery() {
      this.queryParams.currentPage = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    handleUpdate(row) {
      this.reset();
      console.log(row);
      const theId = row.theid;
      getData(theId).then((response) => {
        this.form = response.result;
        // this.form.rules = JSON.parse(response.result.rules);

        this.open = true;
        this.$set(this.dateRange, 0, response.result.startTime);
        this.$set(this.dateRange, 1, response.result.endTime);
        console.log("this.dateRange2", this.dateRange);
        this.title = "修改";
      });
    },
    resetRelease() {
      this.openPublish = {
        theid: undefined, //id
        reviewerId: this.$store.state.userInfo.theid,
        reviewer: this.$store.state.userInfo.thename,
        reviewTime: "",
      };
    },
    // 发布
    handleRelease(row) {
      console.log(row);
      this.openPublish = true;
      this.formPublish.theid = row.theid;
      console.log(this.formPublish.theid);
    },
    submitPublish() {
      getPublish(this.formPublish).then((response) => {
        console.log(response);
        if (response.code === 200) {
          this.msgSuccess("发布成功");
          this.getList();
        }
      });
      this.openPublish = false;
      this.formPublish.reviewTime = "";
    },
    cancelPublish() {
      this.openPublish = false;
    },
    // 取消发布
    Unpublish(row) {
      const theid = row.theid || this.ids;
      this.$confirm("是否确认取消发布?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          // 调接口
          return getUnpublish(theid);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("取消成功");
        });
    },
    submitForm() {
      console.log("this.form", this.form);
      // this.form.rules = JSON.stringify(this.form.rules);
      if (this.dateRange != null) {
        this.form.startTime = this.dateRange[0];

        this.form.endTime = this.dateRange[1];
      }
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.theid != undefined) {
            updateData(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addData(this.form).then((response) => {
              this.msgSuccess("添加成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    cancel() {
      this.open = false;
      this.reset();
    },
    reset() {
      this.form = {
        typeId: undefined, //考试类型 id
        typeVal: undefined, //考试类型
        thePic: undefined, // 考试图片
        title: undefined, //考试名称
        startTime: undefined, //考试开始时间
        endTime: undefined, //考试结束时间
        departmentId: undefined, //考试部门 id
        department: undefined, //考试部门
        shiftId: undefined, //考试班组 id
        shift: undefined, //考试班组
        personnelNum: undefined, // 考试人数
        instructions: undefined,
        taskType: 1, //任务类型 1-独立考试 2-培训考试
        // rules: {
        //   titleName: undefined,
        //   typeId: undefined,
        //   singleNum: 0,
        //   singleVal: 0,
        //   multipleNum: 0,
        //   multipleVal: 0,
        //   judgNum: 0,
        //   judgVal: 0,
        //   completionNum: 0,
        //   completionVal: 0,
        // },
      };
      this.dateRange = [];
      this.resetForm("form");
    },

    handleDelete(row) {
      const theId = row.theid || this.ids;
      this.$confirm("是否确认删除?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          // 调接口
          return delData(theId);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        });
    },
    handleStatusChange(row) {
      console.log("row--", row);
      let text = row.enable === 0 ? "启用" : "停用";
      this.$confirm("是否确认" + text + '"?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          // 调接口 改变状态值
          return getEnable(row.theid, row.enable);
        })
        .then(() => {
          this.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.enable = row.enable === 0 ? 1 : 0;
        });
    },
    // 生成二维码
    handleCode(row) {
      this.qrcode = row.examinationCode;
      this.open4 = true;
      console.log("row---", row);
      console.log("this.qrcode---", this.qrcode);
    },

    changScore() {
      let val1 = Number(this.form.rules.singleVal),
        val2 = Number(this.form.rules.multipleVal),
        val3 = Number(this.form.rules.judgVal),
        val4 = Number(this.form.rules.completionVal);
      let totalScore = val1 + val2 + val3 + val4;
      this.$set(this.form, "totalScore", totalScore);
      // this.form.totalScore = val1 + val2 + val3 + val4
      console.log(val1, val2, val3, val4);
      console.log(this.form.totalScore);
    },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.userId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    handleColumnsConfig() {
      // (this.title1 = "选择"), (this.open1 = true);
      this.open3 = true;
      this.questbank = false;
    },
    handleRandom() {
      this.open3 = false;
      this.questbank = true;
    },
    // 选择题库
    Multiple() {
      this.open3 = true;
    },
    // 查看试卷
    handleSee(row) {
      const paperId = row.paperId;
      getPaper(paperId).then((response) => {
        this.examPaper = response.result;
        let obj = response.result.questionList;

        // let obj = JSON.parse(JSON.stringify(response.result.questionList))
        let questionList = [
          { title: "", children: [] },
          { title: "", children: [] },
          { title: "", children: [] },
          { title: "", children: [] },
        ];
        Object.keys(obj).forEach((key) => {
          if (
            obj[key].title.indexOf("单选题") != -1 &&
            obj[key].children.length > 0
          ) {
            questionList[0] = obj[key];
          } else if (
            obj[key].title.indexOf("多选题") != -1 &&
            obj[key].children.length > 0
          ) {
            questionList[1] = obj[key];
          } else if (
            obj[key].title.indexOf("判断题") != -1 &&
            obj[key].children.length > 0
          ) {
            questionList[2] = obj[key];
          } else if (
            obj[key].title.indexOf("填空题") != -1 &&
            obj[key].children.length > 0
          ) {
            questionList[3] = obj[key];
          }
        });
        this.questionList = questionList;
      });
      this.open2 = true;
    },
    // 关闭查看试卷
    closeSee() {
      this.examPaper = {};
      this.questionList = [
        { title: "", children: [] },
        { title: "", children: [] },
        { title: "", children: [] },
        { title: "", children: [] },
      ];
    },
    // 班组 弹框
    handleTeam(row) {
      this.personParams.theid = row.theid;
      this.openperson = true;
      this.title = "任务消息数据";
      this.getPersonList();
    },
    getPersonList() {
      this.personLoading = true;
      getCrewpopel(this.personParams).then((res) => {
        this.ispeople = res.result.personnelType;
        this.personList = res.result.rows;
        this.personTotal = res.result.total;
        this.personLoading = false;
      });
    },
    // 数组去重
    unique(arr) {
      // 利用对象访问属性的方法，判断对象中是否存在key
      var result = [];
      var obj = {};
      for (var i = 0; i < arr.length; i++) {
        if (!obj[arr[i].theid]) {
          result.push(arr[i]);
          obj[arr[i].theid] = true;
        }
      }
      return result;
    },
    // 题库
    handleQuest(row) {
      this.questbank = true;
      this.title = "题库设置";
    },
    // 跳转子页面
    handleTestPaper(row) {
      const userId = row.userId || this.ids;
      this.$router.push({ path: "problemTest", query: { id: row.deptId } });
    },
    changeDate(val) {
      if (val != null) {
        this.$set(this.form, "startTime", val[0]);
        this.$set(this.form, "endTime", val[1]);
      }
    },
  },
};
</script>

<style scoped lang="scss">
.judge {
  margin-top: 10px;
}
.checktitle {
  width: 100%;
  display: flex;
  font-size: 15px;
  color: red;
  margin-bottom: 20px;
  border-bottom: 1px solid red;
  padding-bottom: 10px;
  p {
    margin-right: 10%;
  }
}
.multiple {
  margin: 0 0 0 20px;
}
.side {
  position: relative;
}
.side /deep/ .el-input {
  width: 48%;
}
.side /deep/ .el-input:last-child {
  position: absolute;
  right: 0;
}
.el-table .active {
  color: #409eff;
  cursor: pointer;
  text-decoration: underline;
}
// 查看试题
.topickinds {
  margin-bottom: 20px;
  .topic {
    margin-top: 20px;
    .topiclist {
      margin-top: 20px;
      input {
        border-bottom: 1px solid;
      }
    }
    .option {
      margin-top: 10px;
    }
  }
}

.qrcode ::v-deep .el-dialog__body {
  padding: 0 20px 20px;
  display: flex;
  justify-content: center;
  img {
    margin: 20px 0;
    width: 240px;
    height: auto;
  }
}
/deep/ .el-input el-input--suffix {
  width: 100%;
}

// 查看试卷  禁用之后样式修改
.topickinds .topic .option {
  display: block;
}
/deep/ .el-radio__input.is-disabled + span.el-radio__label {
  color: #606266;
  cursor: not-allowed;
}
/deep/ .el-radio__input.is-disabled .el-radio__inner,
.el-radio__input.is-disabled.is-checked .el-radio__inner {
  background-color: #fff;
  border-color: #dcdfe6;
}
/deep/ .el-checkbox__input.is-disabled + span.el-checkbox__label {
  color: #606266;
  cursor: not-allowed;
}
</style>

